
#include "IntegerItem.h"
#include "Application.h"
#include "hgeUtil.h"

//
// Constructor
//

IntegerItem::IntegerItem(int _id, float x, float y, int initialValue, int _min, int _max, DWORD _textColor)
{
	id = _id;
	value = initialValue;
	textColor = _textColor;
	min = _min;
	max = _max;

	bStatic = false;
	bVisible = true;
	bEnabled = true;
	decreasedLast = false;

	// Quads
	InitQuad(buttonL, leftArrow);
	InitQuad(buttonR, rightArrow);
	SetQuadRect(buttonL, x,    y+12, x+15, y+27);
	SetQuadRect(buttonR, x+20, y+12, x+35, y+27);
	SetQuadTexCo(buttonL);
	SetQuadTexCo(buttonR);

	// Rect
	rect.Set(x, y+12, x+35, y+27);
}

//
// Render
//

void IntegerItem::Render()
{
	GetSmallFont()->SetColor(textColor);
	GetSmallFont()->printf(buttonL.v[0].x+17, buttonL.v[0].y-12, HGETEXT_CENTER, "%d", value);
	hge->Gfx_RenderQuad(&buttonL);
	hge->Gfx_RenderQuad(&buttonR);
}

//
// MouseLButton
//

bool IntegerItem::MouseLButton(bool bDown)
{
	if(bDown)
	{
		float x, y;
		hge->Input_GetMousePos(&x, &y);

		if(x < rect.x1+17.5f)
		{
			if(value-1 >= min)
			{
				value--;
				decreasedLast = true;
			}
		}
		else
		{
			if(value+1 <= max)
			{
				value++;
				decreasedLast = false;
			}
		}

		return true;
	}
	return false;
}